package com.agv.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.agv.core.dao.cxp.ILigasDao;
import com.agv.core.exception.AgvException;

import com.agv.core.objectDomain.PropiedadesCampo;


public class ShowLigasAction extends Action{

	
	public ActionForward execute(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response)throws AgvException{
		
		String nombreDao = request.getParameter("beanLigasDao");
		String valorPK = "3";//request.getParameter("valorPKLiga");
		
		WebApplicationContext springCtx = WebApplicationContextUtils.getWebApplicationContext( this.getServlet().getServletContext() );
		ILigasDao dao =  (ILigasDao)springCtx.getBean(nombreDao);
		
		Object[] params = new Object[]{valorPK};
		
		List<PropiedadesCampo> datosLiga= dao.getDatosLiga(params);
		request.setAttribute("datosLiga", datosLiga);
		request.setAttribute("numCampos", datosLiga.size());
		
		return mapping.findForward("liga");
		
	}
	
}
